<{include file="app/header.tpl"}>

<script>
function comments_add (form)
{
    var uid = user_get_uid();

    if (uid == 0)
    {
        return false;
    }


    var message = $('#ipt-message').val();
    var type    = $('#ipt-type').val();
    var nid     = $('#ipt-nid').val();
    var touid   = $('#ipt-touid').val();
    var toid    = $('#ipt-toid').val();

    url = '/api/user/comment?uid=' + uid;

    $.post(url, {'type' : type, 'nid' : nid, 'message' : message, 'toid' : toid, 'touid' : touid }, function (o) {
       if (o && o.status == 0)
       {
           var ul = $('.gongl-xq-pinglun');
           var html = '';

           for (var i = 0; i < o.items.length; ++i)
           {
               x = o.items[i];
               html += '<li class="list">'+
                            '<div class="left"><img src="' + o.items[i].userIcon +'"> </div>'+
                            '<div class="middle">'+
                                '<div class="xinxi">'+
                                    '<p class="title">'+ o.items[i].userName +'</p>'+
                                    '<p class="shuoming">'+ o.items[i].message +'</p>'+
                                '</div>'+
                            '</div>'+
                            '<div class="date">'+ o.items[i].date +'</div>'+
                        '</li>';
           }
           ul.html(html + ul.html());
           return false;
       }
       }, 'json');

    $('#ipt-message').val('');

    return false;
}

$(document).ready(function () {
    $('.replyit').each(function () {
        $(this).click(function () { 
            var name = $(this).prev().text();
            var msg = '@'+name+': ';
            $('#ipt-message').val(msg);
            $('#ipt-toid').val($(this).attr('toid'));
            $('#ipt-touid').val($(this).attr('touid'));
        });
    });
});


</script>

    <{if $comments.total > 0}>
    <!-- 当有评论的时候出现 start -->
    <ul class="gongl-xq-pinglun" style="padding-left: 14px;">
        <{foreach from=$comments.items item="cmt"}>
        <li class="list">
            <div class="left"><img src="<{$cmt.userIcon}>" alt=""></div>
            <div class="middle">
                <div class="xinxi">
                    <p class="title"><span><{$cmt.userName}></span> <span touid="<{$cmt.uid}>" toid="<{$cmt.id}>" class="replyit">回复</span></p>
                    <p class="shuoming"><{$cmt.message}></p>
                </div>

            </div>
            <div class="date"><{$cmt.date}></div>
        </li>
        <{/foreach}>
    </ul>
    <!-- 当有评论的时候出现 end -->
    <{else}>
    <!-- 当评论为空的时候出现 start -->
    <div class="search_gonglue">

        <img src="/resource/skin/img/search_icon.png" width="50" height="50" alt="">

        <p class="prompt">现在还没有评论，限量沙发先到先得哦</p>

     </div>
    <!-- 当评论为空的时候出现 end -->
    <{/if}>

    <div class="cmtForm" style="bottom: 0;">
        <{if $global_user.uid > 0}>
        <form class="oForm" id="form-comments" action="" method="POST" onsubmit="return comments_add(this)">
            <input type="text" class="message" name="message" id="ipt-message" placeholder="输入评论...">
            <input type="hidden" name="type" value="gonglue" id="ipt-type">
            <input type="hidden" name="nid" value="3" id="ipt-nid">
            <input type="hidden" name="toid" value="0" id="ipt-toid">
            <input type="hidden" name="touid" value="0" id="ipt-touid">

            <input class="submit" type="submit" name="submit_op" value="发送">
        </form>
        <{else}>
        <p class="prompt">请登录后再发表评论: <span onclick="user_login()">立即登录</span></p>
        <{/if}>
    </div>
<{include file="app/footer.tpl"}>
